package com.ruoyi.web.controller.printSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.PrinterSettings;
import com.ruoyi.system.service.IPrinterSettingsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 打印机设置，用于管理各门店下档口的打印机配置Controller
 *
 * @author ruoyi
 * @date 2025-05-12
 */
@Api(tags="打印机设置")
@RestController
@RequestMapping("/system/printerSettings")
public class PrinterSettingsController extends BaseController
{
    @Autowired
    private IPrinterSettingsService printerSettingsService;

    /**
     * 查询打印机设置列表
     */
    @ApiOperation("查询打印机设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<PrinterSettings> list = printerSettingsService.selectPrinterSettingsListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出打印机设置列表
     */
    @ApiOperation("导出打印机设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:export')")
    @Log(title = "打印机设置，用于管理各门店下档口的打印机配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<PrinterSettings> list = printerSettingsService.selectPrinterSettingsListByName(storeName);
        ExcelUtil<PrinterSettings> util = new ExcelUtil<PrinterSettings>(PrinterSettings.class);
        util.exportExcel(response, list, "打印机设置，用于管理各门店下档口的打印机配置数据");
    }

    /**
     * 获取打印机设置详细信息
     */
    @ApiOperation("获取打印机设置详细信息")
    @PreAuthorize("@ss.hasPermi('system:settings:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(printerSettingsService.selectPrinterSettingsById(id));
    }

    /**
     * 新增打印机设置列表
     */
    @ApiOperation("新增打印机设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:add')")
    @Log(title = "打印机设置，用于管理各门店下档口的打印机配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PrinterSettings printerSettings)
    {
        return toAjax(printerSettingsService.insertPrinterSettings(printerSettings));
    }

    /**
     * 修改打印机设置列表
     */
    @ApiOperation("修改打印机设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:edit')")
    @Log(title = "打印机设置，用于管理各门店下档口的打印机配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PrinterSettings printerSettings)
    {
        return toAjax(printerSettingsService.updatePrinterSettings(printerSettings));
    }

    /**
     * 删除打印机设置列表
     */
    @ApiOperation("删除打印机设置列表")
    @PreAuthorize("@ss.hasPermi('system:settings:remove')")
    @Log(title = "打印机设置，用于管理各门店下档口的打印机配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(printerSettingsService.deletePrinterSettingsByIds(ids));
    }
}
